/**
 * 行政区划控制器
 */
export default class extends think.BaseController {
  async areaListAction() {
    const areaList = await this.service('sys/AreaService').getAreaList();
    return this.successJson(areaList);
  }

  /**
     * 获取所有表单信息
     *
     * @returns
     */
  async getAllAreaAction() {
    const aj = think.ajaxJson();
    const AreaService = this.service('sys/AreaService');
    const res = await AreaService.getAllArea();
    if (res && res.error) {
      aj.success = false;
      aj.msg = '获取失败';
    } else {
      aj.result = res;
    }
    return this.json(aj);
  }

  /**
     * 获取区域数据将areaCode设置为id
     */
  async queryAreaByAreaCodeAction() {
    const AreaService = this.service('sys/AreaService');
    const area_code = this.post('area_code');
    const res = await AreaService.queryAreaByAreaCode(area_code);
    if (res && res.error) {
      return this.errorJson('查询失败');
    } else {
      return this.successJson(res);
    }
  }

  /**
     * 根据获取区域数据
     */
  async queryAreaByIdAction() {
    const AreaService = this.service('sys/AreaService');
    const area_code = this.post('id');
    const res = await AreaService.queryAreaById(area_code);
    if (res && res.error) {
      return this.errorJson('查询失败');
    } else {
      return this.successJson(res);
    }
  }
}
